﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeacherHelp.Model;

namespace TeacherHelp.DAL
{
    /// <summary>
    /// 题目相关服务
    /// </summary>
    public class ExercisesService
    {
        public string GetExercisesInfoSQL()
        {
            string sql = @"
            select 
                    a.Id,
                    a.Content,
                    a.answer,
                    case a.Difficulty when '1' then '简单' when '2' then '中等' when '3' then '困难' else null end Difficulty,
                    b.[Name] SubjectName,
                    Aoption,
                    Boption,
                    Coption,
                    Doption
            from Exercises a
            left join subjects b on a.SubjectsId = b.Id where 1=1";
            return sql;
        }

        public string GetOrderByDesc()
        {
            string sql = " order by Id desc ";
            return sql;
        }

        public string GetSujbectWhereSQL(int Id)
        {
            return $" and b.Id = {Id}";
        }

        public string GetDifficultyWhereSQL(int difficulty)
        {
            return $" and a.Difficulty = {difficulty}";
        }

        public string GetIdWhereSQL(int Id)
        {
            string sql = $" where Id = {Id}";
            return sql;
        }

        public string GetIdWhereSQL(string Id)
        {
            string sql = $" and a.Id = {Id}";
            return sql;
        }

        public string GetDelExercisesSQL(int id)
        {
            string sql = $" delete from Exercises where Id = {id}";
            return sql;
        }

        public string GetExercisesId(int subjectId)
        {
            var sql = $@"SELECT [Id] FROM [dbo].[Exercises] where SubjectsId = '{subjectId}'";
            return sql;
        }

        public string GetExercises(string whereId)
        {
            var sql = $@"
            SELECT [Id]
                ,[Content]
                ,[SubjectsId]
                ,[Answer]
                ,[Aoption]
                ,[Boption]
                ,[Coption]
                ,[Doption]
            FROM [dbo].[Exercises] WHERE [ID] IN ({whereId})";
            return sql;
        }

        public string GetExercises(int subjectId)
        {
            var sql = $@"
            SELECT [Id]
                ,[Content]
                ,[SubjectsId]
                ,[Answer]
                ,[Difficulty]
                ,[Aoption]
                ,[Boption]
                ,[Coption]
                ,[Doption]
            FROM [dbo].[Exercises]  where SubjectsId = '{subjectId}'";
            return sql;
        }
    }
}
